package com.mzy.linear_struct.hot100.动态规划;

/**
 * @Author: mizy3
 * @Date: 2024/09/07/下午3:25
 * @Description:
 */
public class Pro392判断子序列 {

    public boolean isSubsequence(String s, String t) {
        int[][] dp = new int[t.length() + 1][s.length() + 1];
        for (int i = 1; i < dp.length; i++) {
            for (int j = 1; j < dp[i].length; j++) {
                if (s.charAt(j - 1) == t.charAt(i - 1)) {
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                }else {
                    dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
                }
            }
        }
        for (int i = 0; i < dp.length; i++) {
            for (int j = 0; j < dp[i].length; j++) {
                System.out.print(dp[i][j] + " ");
            }
            System.out.println();
        }
        return dp[dp.length - 1][dp[0].length - 1] == s.length();
    }

/*    public boolean isSubsequence(String s, String t) {
        // s = "abc", t = "ahbgdc"
        char[] sarr = s.toCharArray();
        char[] tarr = t.toCharArray();

        int i = 0, j = 0;
        while (i < t.length()){
            if(j == s.length()) return true;
            if(sarr[i] == tarr[j]){
                j++;
            }
            i++;
        }

        return j == s.length();
    }*/


}
